<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>基本信息</title>
    <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
  <style>
    .xm-select-default{width: 0px !important;}
  </style>
</head>
<body>
<div class="layui-form-pane" style=" width: 750px; text-align: center;margin: 0 auto;">

  <form class="layui-form" style="width: 500px;text-align: center;margin: 0 auto">
    <h2 style="margin: 20px; font-weight: bold">修改学历信息</h2>

    <div class="layui-form-item">
      <label class="layui-form-label">毕业时间</label>
      <div class="layui-input-block" style="width: 400px;">
        <input type="text" name="eduTime" id="eduTime" lay-verify="date" autocomplete="off" placeholder="请输入标题" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">学历</label>
      <div class="layui-input-block" style="width: 400px;">
        <div id="eduGrade"></div>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">毕业院校<span style="color:red;"></span></label>
      <div class="layui-input-block" style="width: 400px;">
        <input type="text" name="eduSchool" autocomplete="off" placeholder="请输入标题" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">专业</label>
      <div class="layui-input-block" style="width: 400px;">
        <input type="text" name="eduSubject" autocomplete="off" placeholder="专业" class="layui-input">
      </div>
    </div>

    <div class="layui-btn-container" style="margin: 35px 10px;position: fixed;bottom: 0;right: 5%;">
      <button type="button" style="width: 100px;" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" lay-submit lay-filter="educationBtn">保存</button>
      <button type="button" style="width: 100px;" class="layui-btn layui-btn-primary layui-btn-radius layui-btn-sm" onclick="closeIframe()">取消</button>
    </div>
  </form>
</div>
</body>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/common/xm-select/xm-select.js"></script>
<script type="text/javascript" src="/common/layer/layer.js"></script>
<script>

  window.onload = function () {
  }


  layui.use(['form','laydate'],function (){

    var laydate = layui.laydate;
    var form = layui.form;

    //赋值表单
    setUserMaterial();


    function setUserMaterial(){
      var eduSchool = $("#eduSchool",parent.document).html();
      var eduSubject = $("#eduSubject",parent.document).html();
      var eduTime = $("#eduTime",parent.document).html();
      var eduGrade = $("#eduGrade",parent.document).html();

      $('input[name = eduSchool]').val(eduSchool);
      $('input[name = eduSubject]').val(eduSubject);
      $('input[name = eduTime]').val(eduTime);
      $("#eduGrade").val(eduGrade);
      laydate.render({
        elem: '#eduTime'
      });

      var code = getGradeCode(eduGrade);
      var eduGradeSelect = xmSelect.render({
        el: '#eduGrade',
        radio: true,
        model: {
          icon: 'hidden',
          label: {
            type: 'text'
          }
        },
        clickClose: true, //点击之后关闭
        initValue: [code],
        tips: '学历',
        theme: {
          color: '#0081ff',
        },
        data: [
          {name:'博士',value: '01'},
          {name:'硕士',value: '02'},
          {name:'本科',value: '03'},
          {name:'专科',value: '04'},
          {name:'高中',value: '05'},
          {name:'高中以下',value: '06'},
        ]
      })

      form.render();
    }

    function getGradeCode(grade){
      var code;
      switch (grade){
        case "博士":
          code = "01";
          break;
        case "硕士":
          code = "02";
          break;
        case "本科":
          code = "03";
          break;
        case "专科":
          code = "04";
          break;
        case "高中":
          code = "05";
          break;
        case "高中以下":
          code = "03";
          break;
      }
      return code;
    }


    form.on('submit(educationBtn)',function (obj){

      var userId = $("#userId",parent.document).val();
      console.log(obj.field)
      $.ajax({
        url: "/user/index/saveEducation",
        data:{
          "userId":userId,
          "eduSchool": obj.field.eduSchool,
          "eduSubject": obj.field.eduSubject,
          "eduTime": obj.field.eduTime,
          "eduGrade": obj.field.select,
        },
        type: "post",
        dataType: "json",
        success:function (res){
          if (res.state == false){
            layer.msg(res.msg,{icon:2,time:800})
          }else {
            layer.msg("保存成功",{icon:1,time:800})
            var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
            parent.layer.close(index);//执行关闭
            parent.location.reload();
          }
        }
      })
    })
  })
  function closeIframe(){
    var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
    parent.layer.close(index);//执行关闭
  }
</script>
</html>
